#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import rospy
from std_msgs.msg import String

class ColorResultSubscriber:
    def __init__(self):
        rospy.init_node('result_subscriber', anonymous=True)
        # 订阅颜色检测结果话题
        self.color_sub = rospy.Subscriber('/multi_template_matcher/detected_color', String, self.color_callback)
        self.current_color = None

    def color_callback(self, msg):
        """颜色检测结果回调函数"""
        # 更新当前检测到的颜色
        self.current_color = msg.data
        #self.print_result()

    def print_result(self):
        """打印当前检测结果"""
        if self.current_color:
           print(f"检测到颜色: {self.current_color}")
        else:
           print("未检测到有效颜色")

if __name__ == '__main__':
    subscriber = ColorResultSubscriber()
    rospy.spin()    
